// const { app, BrowserWindow } = require('electron')

// const createWindow = () => {
//   const win = new BrowserWindow({
//     width: 800,
//     height: 600
//   })

//   win.loadFile('index.html')
// }
// app.on('ready', () => {
//     createWindow()
// })

const { app, BrowserWindow, dialog } = require('electron/main')
const path = require('node:path')
const createWindow = () => {
    let win = new BrowserWindow({
        width: 1600,
        height: 900,
        icon: path.join(__dirname, 'favicon.ico'),

        webPreferences: {
            preload: path.join(__dirname, 'preload.js')
        }
    })

    win.loadFile('./dist/index.html')
    //   win.loadURL('http://192.168.110.62:8082/')
    win.menuBarVisible = false//隐藏菜单栏
    //   win.fullScreen = true
    win.on('close', function(event){
        const choice = dialog.showMessageBoxSync(win, {
            type: 'question',
            buttons: ['取消', '确定'],
            defaultId: 1,
            title: '提示',
            message: '确定要关闭窗口吗?'
        })

        if (choice !== 1){
            event.preventDefault() // Prevent the window from closing
        }
    })

    win.on('closed', function(){
        win = null
    })
}

app.whenReady().then(() => {
    createWindow()

    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0){
            createWindow()
        }
    })
})

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin'){
        app.quit()
    }
})